home *** CD-ROM | disk | FTP | other *** search
/ Chip 1996 November / Chip 11-96.iso / workshop / other / testlin / testlin.exe / LINUX / SBIN / SWAPCONF.{_L < prev    next >
Encoding:
Text File  |  1996-03-01  |  2.0 KB  |  90 lines

  1. #!/bin/sh
  2.  
  3. # Ask user a permission
  4. cat <<EOF > /tmp/tmpmsg
  5. Do you want to setup a swap file ?
  6.  
  7. The use of disk space as virtual memory is
  8. recommended if you have less than 16 Mb of memory.
  9.  
  10. EOF
  11.  dialog --title "SETUP SWAPSPACE" --yesno "`cat /tmp/tmpmsg`" 8 70 2> /tmp/SetQuery
  12.  if [ $? != 0 ]; then
  13.    exit 0;
  14.  fi
  15.  
  16. rm /tmp/tmpmsg /tmp/SetQuery
  17.  
  18. # Setup swap space:
  19. /sbin/swapoff /dev/swapfile
  20. while [ "$SWAPSIZE" = "" ]; do
  21. DF=`df /dev`
  22. cat << EOF > /tmp/tmpmsg
  23. This is how much you have disk space:
  24. $DF
  25.  
  26. How big swap file would you like to create?
  27.  
  28. To give you an idea, you will specify a number such as 4096 if
  29. you want to use 4 megabytes of your DOS partition for a swap
  30. file. Assuming you have 4 megabytes of RAM, you will need a swap
  31. file of size 4096 to run X. I recommend 8192 for full use.
  32.  
  33. Enter swap file size: 
  34. EOF
  35.  dialog --title "ENTER SIZE OF SWAPFILE" --inputbox "`cat /tmp/tmpmsg`" 20 70 \
  36.  2> /tmp/SeSSize
  37.  if [ $? = 1 -o $? = 255 ]; then
  38.   rm -f /tmp/SeSSize /tmp/tmpmsg
  39.   exit
  40.  fi
  41.  SWAPSIZE="`cat /tmp/SeSSize`"
  42.  rm -f /tmp/SeSSize /tmp/tmpmsg
  43. done
  44.  
  45. dialog --title "CREATING SWAPFILE" --infobox "\n\
  46. Creating a ${SWAPSIZE}K swapfile in your /dev directory.\n\
  47. " 5 70
  48.  
  49. dd if=/dev/zero of=/dev/swapfile bs=1024 count=$SWAPSIZE
  50. sync
  51. if [ ! $? = 0 ]; then
  52.  sleep 5
  53.  dialog --title "WHOOOOOPS" --msgbox "\n\
  54. Whoooops. I think there was an error there.\n\
  55. You'll probably have to reboot and try again, but\n\
  56. you might want to continue anyway.\n\
  57. \n\
  58. Press enter to continue. You may see a whole bunch of errors.\n\
  59. \n\
  60. Try not to look.\n\
  61. " 12 70
  62.  
  63. sleep 15
  64. fi
  65.  
  66. dialog --title "ACTIVATING SWAP" --infobox "\n\
  67. Running mkswap on the new swapfile and\n\
  68. activating swap partition\n\
  69. " 6 70
  70.  
  71. mkswap /dev/swapfile $SWAPSIZE
  72. sync
  73. swapon /dev/swapfile
  74. if fgrep "/dev/swapfile" /etc/fstab > /dev/null 2>&1
  75. then
  76.   :
  77. else
  78.   echo "/dev/swapfile     swap      swap         defaults" >> /etc/fstab
  79.   echo "swapon /dev/swapfile" >> /etc/rc.d/rc.S
  80. fi
  81.  
  82. sleep 5
  83.  
  84. MEM=`/bin/free`
  85. dialog --title "MEMORY STATUS" --msgbox "\n\
  86. $MEM\n\
  87. You should see your swapspace indicated on the table above.\n\
  88. " 10 70
  89.  
  90.